<?php #coding: utf-8 æ ø å ?

class Type_spec_model extends CI_Model {
	public $type_spec;
	public $type_spec_data = array();

	public function specificer_type($id,$type) {

//		$this->load->model('element/type_spec_model');

		//$this->under = $this->element->find_under($id);

		//echo $id;

		if($type == "entitet") {
			$this->load->model("core/entitet");
			$entitet = new entitet();
			$entitet->find_type_kvant($id);
			$type_kvant = $entitet->type_kvant;
			//$this->type_kvant = $type_kvant;


			$this->load->model("core/element");


			if($type_kvant == "individ") {

				$this->load->model("core/player_character");
				$player_character = new player_character;
				$player_character->find_rollespiller($id);
				$rollespiller = $player_character->rollespiller;
				if($player_character->id_rollespiller != 0) {
 					$this->type_spec = "player_character";
					$this->rollespiller = $player_character->rollespiller;
					$this->id_rollespiller = $player_character->id_rollespiller;
				}
				else{
					$this->type_spec = "individ";
				}
				$this->type_view = "individ";
				$this->type_spec_data = $this->find_individ_data($id);
			}

			elseif($type_kvant == "gruppe") {
				//echo "grupppe";
				$this->load->model("core/gruppe");
				$gruppe = new gruppe();
				$gruppe->find_type($id);
			
				/*if(!empty($gruppe->type)) {
					$this->load->model("core/gruppe_styring");
					
					$this->type_spec = $gruppe->type;
					$this->type_view = "gruppe";								
					$this->type_spec_data = $this->find_gruppe_spec_data($id);
				}

				else{*/

					$gruppe->er_race($id);
					$this->type_view = "gruppe";					
					$er_race = $gruppe->er_race;


					if($er_race == TRUE) {
						$this->type_spec = "race";
						$this->type_spec_data = array(); // 	
					}

					else {
					$this->type_spec = "gruppe";
					$this->type_spec_data = array();
					}

//				}
			}
		}
		elseif($type == "sted") {
			$this->load->model("core/sted");
			$sted = new sted();
			//echo "sted";
			$this->type_view = "sted";
			//$sted->find_sted_type($id);
			$this->type_spec = "sted";
			$this->type_spec_data = $this->find_sted_spec_data($id);
		}

		elseif($type == "begivenhed") {
			$this->load->model("core/begivenhed");
			$begivenhed = new begivenhed();
			$begivenhed->er_rpg_element($id);
			if($begivenhed->rpg_element_form != FALSE) {
				$this->type_spec = $begivenhed->rpg_element_form;
			}
			else { $this->type_spec = $type; } 

			$this->type_view = $type;
			$this->type_spec_data = $this->find_begivenhed_spec_data($id);
		}

	}



	public function find_begivenhed_spec_data($id) {

		$this->load->model("core/begivenhed");
		$begivenhed = new begivenhed();
		$begivenhed->find_deltagere($id);
		$begivenhed->find_steder($id);
//		$data['birth_ord'] = $begivenhed->birth_ord;
//		$data['death_ord'] = $begivenhed->death_ord;  		
		$data['deltagere_individer'] = $begivenhed->deltagere_individer;  
		$data['deltagere_grupper'] = $begivenhed->deltagere_grupper;  
		$data['deltagere_individer_count'] = count($data['deltagere_individer']);  
		$data['deltagere_grupper_count'] = count($data['deltagere_grupper']); 
		$data['steder'] = $begivenhed->steder;  

		return $data;

	}






	public function find_individ_data($id)
	{
		//echo "This is sparta";

	// $navigation = "core/".$navigation;
		$this->load->model("core/individ");
		$this->load->model("core/player_character");
		$individ = new player_character();
//		$data['birth_ord'] = $individ->birth_ord;
//		$data['death_ord'] = $individ->death_ord;

		$individ->find_oplevelser($id);	
		$individ->find_koen($id);
		$individ->find_race($id);
		$individ->find_rollespiller($id);
		$individ->find_foraeldrer($id);
		$individ->find_boern($id);
		$individ->find_level($id);
		$individ->find_profession($id);
		$individ->find_alle_titler($id);
		$individ->find_oplevelser($id);
		
		//$element->find_sidste_stats($id,"temp",);
  

		$data['foraeldrer'] = $individ->foraeldrer;
		$data['boern'] = $individ->boern;
		$data['rollespiller'] = $individ->rollespiller;
		$data['race'] = $individ->race;
		$data['race_id'] = $individ->race_id;
		$data['racial_stat_bonus'] = $individ->racial_stat_bonus;
		$data['level'] = $individ->level;
		$data['profession'] = $individ->profession;
		$data['koen'] = $individ->koen;
		$data['titler'] = $individ->alle_titler;
		$data['titler_ider'] = $individ->alle_titler_ider;
		$data['oplevelser'] = $individ->oplevelser;
		/*$sidste_temp_stats = $element->sidste_stats;

		if($sidste_temp_stats != 0){
			asort($sidste_temp_stats);
		}

		$data['sidste_temp_stats'] = $sidste_temp_stats;
	
		$data['views_left'] = array();*/
//echo "Hallo find individ data";
		return $data;

	}




	function find_gruppe_spec_data($id) {

		$data = array();

		$this->load->model("core/gruppe_styring");
		$this->load->model("core/gruppe");

		$gruppe = new gruppe();
		$gruppe->find_type($id);
		$gruppe_type_id = $gruppe->type_id;	
		$gruppe = new gruppe_styring();
		
		//$data['titler'] = $this->gruppe_styring->find_titler_indenfor_gruppe($gruppe_type_id);
//		$data['birth_ord'] = $gruppe->birth_ord;
//		$data['death_ord'] = $gruppe->death_ord;  		

		return $data;


	}

	function find_sted_spec_data($id) {

		$data = array();

		//$this->load->model("core/gruppe_styring");
		$this->load->model("core/sted");

		$sted = new sted();
		$sted->find_historie($id);
		//$sted_type_id = $sted->type_id;	
		//$sted = new sted_styring();
		
		$data['historie'] = $sted->historie;
//		$data['birth_ord'] = $sted->birth_ord;
//		$data['death_ord'] = $sted->death_ord;  		

		return $data;


	}


	function skriv_type_spec($id,$type_spec) {
		
		$data = array
		(
			'type_spec' => $type_spec
		);
		
		$this->db->where('id', $id);
		$this->db->update("element", $data);
		
	}



}

?>
